#include <dbg.h>

#include <cassert>

using namespace std;

class Solution {
public:
    vector<int> getAverages(vector<int>& nums, int k) {
        int n = nums.size();
        vector<int> res(n, -1);
        int sum = 0;  // 窗口和
        for (int i = 0; i < n; ++i) {
            sum += nums[i];
            dbg(sum);
            if (i < k * 2) {  // 窗口还没满
                continue;
            }
            res[i - k] = sum / (k * 2 + 1);  // 窗口满了，计算平均值
            sum -= nums[i - k * 2];          // 窗口满了，减去最左边的数
            dbg(res);
        }
        return res;
    }
};

int main() {
    Solution s;

    vector<int> nums1 = {7, 4, 3, 9, 1, 8, 5, 2, 6};
    vector<int> nums2 = {100000};
    vector<int> nums3 = {8};

    int k1 = 3;
    int k2 = 0;
    int k3 = 100000;

    vector<int> res1 = {-1, -1, -1, 5, 4, 4, -1, -1, -1};
    vector<int> res2 = {100000};
    vector<int> res3 = {-1};

    assert(s.getAverages(nums1, k1) == res1);
    assert(s.getAverages(nums2, k2) == res2);
    assert(s.getAverages(nums3, k3) == res3);

    return 0;
}